package com.jeesite.modules.yzw.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.web.BaseController;
import com.jeesite.common.web.http.HttpClientUtils;
import com.jeesite.common.web.http.ServletUtils;
import com.jeesite.modules.annotation.RepeatSubmit;
import com.jeesite.modules.backlog.entity.DcSupBacklog;
import com.jeesite.modules.backlog.service.DcSupBacklogService;
import com.jeesite.modules.msg.entity.MsgPush;
import com.jeesite.modules.msg.service.MsgPushService;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.utils.OkHttpUtils;
import com.jeesite.modules.utils.SM3Utils;
import com.jeesite.modules.yzw.config.YzwProperties;
import com.jeesite.modules.yzw.constant.Constant;
import com.jeesite.modules.yzw.entity.Pager;
import com.jeesite.modules.yzw.service.YzwClient;
import com.jeesite.modules.yzw.service.YzwService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.MessageDigest;
import java.util.*;

/**易政网Controller
 * @author guohusong
 * @version 1.0
 * @date 2022/4/30 9:43
 */

@Controller
@RequestMapping(value = "urc/yzw")
public class YzwController extends BaseController {
    @Value("${server.servlet.context-path}")
    private String url;

    @Resource
    private YzwProperties yzwProperties;

    @Resource
    private YzwClient yzwClient;

    @Resource
    private YzwService yzwService;

    @Resource
    private MsgPushService msgPushService;

    @Resource
    private DcSupBacklogService dcSupBacklogService;

    /**
     * 易政网登录，跳转过来单点登录
     *
     * @param token
     * @param request
     * @return
     */
    @RequestMapping("/login")
    public String yzwLogin(@RequestParam(value = "token", required = false) String token,
                           HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
        //开启易政网功能
        if (yzwProperties.isYzwFunc()) {
            if (StringUtils.isEmpty(token) || StringUtils.equals(token, "undefined")) {
                request.setAttribute("message", "请求参数中token不存在");
                request.getRequestDispatcher("/error/403").forward(request, response);
            } else {
                JSONObject resultObj = yzwClient.checkLxLoginObj(Constant.TestData.CURRENT_USER_ID, token);
                System.out.println("---易政网返回数据---" + resultObj.toJSONString());
                if (null != resultObj) {
                    //String id = resultObj.getString("ucUserId");
                    String id = resultObj.getString("id");
                    Map paramMap = new HashMap();
                    paramMap.put("status", "0");
                    paramMap.put("extendS2", id);
                    Map user = yzwService.findYzwList(paramMap);
                    if (null != user) {
                        String userName = (String) user.get("login_code");
                        String ssoToken = UserUtils.getSsoToken(userName);
                        //有工作门户菜单跳转到工作门户上，否则跳转默认页面
                        if (isHavingPortal((String) user.get("user_code"))) {
                            return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index#" + url + "/a/home/homePage/workPortal";
                        } else {
                            return REDIRECT + "/sso/" + userName + "/" + ssoToken;
                        }

                    } else {
                        request.setAttribute("message", "用户不存在，请联系管理员");
                        request.getRequestDispatcher("/error/403").forward(request, response);
                    }
                } else {
                    request.setAttribute("message", "易政网登录失败");
                    request.getRequestDispatcher("/error/403").forward(request, response);
                }
            }
        } else {
            request.setAttribute("message", "易政网登录开关未开启!");
            request.getRequestDispatcher("/error/403").forward(request, response);
        }
        return REDIRECT + "/a/login";
    }

    /**
     * 单点登录获取令牌 - 移动端
     *
     * @param request
     * @param response
     * @return
     */
    @RepeatSubmit
    @RequestMapping(value = "ssoToken")
    public String getSsoToken(@RequestParam(value = "token", required = false) String token, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //开启易政网功能
        if (yzwProperties.isYzwFunc()) {
            if (StringUtils.isEmpty(token)) {
                request.setAttribute("message", "请求参数中token不存在");
                request.getRequestDispatcher("/error/403").forward(request, response);
            } else {
                JSONObject resultObj = yzwClient.checkLxLoginObj(Constant.TestData.CURRENT_USER_ID, token);
                if (null != resultObj) {
                    String id = resultObj.getString("id");
                    Map paramMap = new HashMap();
                    paramMap.put("status", "0");
                    paramMap.put("extendS2", id);
                    Map user = yzwService.findYzwList(paramMap);
                    if (null != user) {
                        String userName = (String) user.get("login_code");
                        String ssoToken = UserUtils.getSsoToken(userName);
                        Map userMap = new HashMap();
                        userMap.put("username", userName);
                        userMap.put("token", ssoToken);
                        return ServletUtils.renderResult(response, Global.TRUE, text("执行成功"), userMap);
                    } else {
                        request.setAttribute("message", "用户不存在，请联系管理员");
                        request.getRequestDispatcher("/error/403").forward(request, response);
                    }
                } else {
                    request.setAttribute("message", "登录失败");
                    request.getRequestDispatcher("/error/403").forward(request, response);
                }
            }
        } else {
            request.setAttribute("message", "登录开关未开启!");
            request.getRequestDispatcher("/error/403").forward(request, response);
        }
        return REDIRECT + "/a/login";
    }

    /**
     * 判断当前用户是否有工作门户菜单
     *
     * @return
     */
    private boolean isHavingPortal(String userCode) {
        Map map = new HashMap();
        map.put("userCode", userCode);
        map.put("menuName", "工作门户");
        return this.yzwService.findYzwMenu(map);
    }

    /**
     * 易政网待办消息点击【更多】时跳转
     * 点击消息时，跳转到消息详情
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/news")
    public String news(@RequestParam(value = "more", required = false) String more,
                       @RequestParam(value = "token", required = false) String token,
                       @RequestParam(value = "msgId", required = false) String msgId,
                       HttpServletRequest request,
                       HttpServletResponse response) throws ServletException, IOException {
        // 开启易政网功能
        if (yzwProperties.isYzwFunc()) {
            if (StringUtils.isEmpty(token)) {
                request.setAttribute("message", "请求参数中token不存在");
                request.getRequestDispatcher("/error/403").forward(request, response);
            } else {
                // 访问易政网接口，获取用户的易政网id
                JSONObject resultObj = yzwClient.checkLxLoginObj(Constant.TestData.CURRENT_USER_ID, token);
                if (null != resultObj) {
                    String id = resultObj.getString("id");
                    Map paramMap = new HashMap();
                    paramMap.put("status", "0");
                    paramMap.put("extendS2", id);
                    // 获取用户在我们系统的信息
                    Map user = yzwService.findYzwList(paramMap);
                    if (null != user) {
                        String userName = (String) user.get("login_code");
                        String ssoToken = UserUtils.getSsoToken(userName);
                        if (StringUtils.isBlank(msgId)) {
                            // 没有消息id，则跳转到消息列表
                            return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index#" + url + "/a/backlog/dcSupBacklog/backlogList";
                        } else {
                            if ("1".equals(Global.getConfig("sys.yzw.switch"))) {
                                // 站内信跳转
                                // 有消息id，获取消息按钮跳转地址
//                                String msgButtonHref = this.getMsgButtonHref(msgId);
//                                if (StringUtils.isBlank(msgButtonHref)) {
//                                    // 跳转到消息详情
//                                    return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index#" + url + "/a/msg/readMsg?id=" + msgId;
//                                } else {
//                                    // 跳转到消息按钮地址
//                                    return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index#" + url + msgButtonHref;
//                                }
                                 return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index#" + url + "/a/backlog/dcSupBacklog/backlogList";

                            } else {
                                // 待办跳转
                                DcSupBacklog dcSupBacklog = dcSupBacklogService.get(msgId);
                                // 只跳转待处理的待办
                                if ("1".equals(dcSupBacklog.getDataStatus())) {
                                    String msgButtonHref = dcSupBacklog.getBacklogHref();
                                    return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index#" + url + msgButtonHref;
                                } else {
                                    // 跳转到页面
                                    return REDIRECT + "/sso/" + userName + "/" + ssoToken + "?url=/a/index";
                                }
                            }
                        }
                    } else {
                        request.setAttribute("message", "用户不存在，请联系管理员");
                        request.getRequestDispatcher("/error/403").forward(request, response);
                    }
                } else {
                    request.setAttribute("message", "登录失败");
                    request.getRequestDispatcher("/error/403").forward(request, response);
                }
            }
        } else {
            request.setAttribute("message", "登录开关未开启!");
            request.getRequestDispatcher("/error/403").forward(request, response);
        }
        return REDIRECT + "/a/login";
    }

    /**
     * 消息分页查询，易政网查询当前登录用户的待办信息
     * 使用参数【sys.yzw.switch】控制是否推送，其中0为关闭、1为推送站内信、2为推送待办
     *
     * @param pager
     * @param type  0:文本类，1:待办事项
     * @param token
     * @param args
     * @return
     */
    @RequestMapping("/pageIflytekMsgDetail")
    public Map<String, Object> pageIflytekMsgDetail(Pager pager, int type, String token, String args) {
        System.out.println("---易政网待办参数 type:---" + type + " token:" + token + " args:" + args);
        Map<String, Object> message = new HashMap<>();
        // 获取参数
        String config = Global.getConfig("sys.yzw.switch");
        // 是否启用易政网首页接口推送功能：0为关闭
        if (!"0".equals(config)) {
            // 开启易政网功能
            if (yzwProperties.isYzwFunc()) {
                // 校验token
                if (StringUtils.isNotBlank(token)) {
                    // 验证当前登录用户
                    JSONObject resultObj = yzwClient.checkLxLoginObj(Constant.TestData.CURRENT_USER_ID, token);
                    if (null != resultObj) {
                        // 获取当前登录用户在本系统中的信息
                        String id = resultObj.getString("id");
                        Map paramMap = new HashMap();
                        paramMap.put("status", "0");
                        paramMap.put("extendS2", id);
                        Map user = yzwService.findYzwList(paramMap);
                        if (null != user) {
                            Pager resultPager;
                            if ("1".equals(config)) {
                                // 推送站内信
                                resultPager = this.getMsgDetail1(pager, user);
                            } else {
                                // 推送待办
                                resultPager = this.getMsgDetail2(pager, user);
                            }
                            // 构建返回值
                            message.put("code", "000000");
                            message.put("message", "成功");
                            message.put("data", resultPager);
                            message.put("success", "true");
                        } else {
                            message.put("code", "999999");
                            message.put("message", "用户不存在，请联系管理员");
                        }
                    } else {
                        message.put("code", "999999");
                        message.put("message", "易政网信息验证失败");
                    }
                } else {
                    message.put("code", "999999");
                    message.put("message", "请求参数中token不存在，请刷新后重试");
                }
            } else {
                message.put("code", "999999");
                message.put("message", "易政网登录开关未开启");
            }
        } else {
            message.put("code", "999999");
            message.put("message", "接口暂时关闭");
        }

        return message;
    }

    /**
     * 获取待办角标数，易政网查询当前登录用户的待办信息数
     * 使用参数【sys.yzw.switch】控制是否推送，其中0为关闭、1为推送站内信、2为推送待办
     *
     * @param token
     * @param request
     * @return
     */
    @RequestMapping("/marker")
    public Map<String, Object> marker(String token, HttpServletRequest request) {
        Map<String, Object> message = new HashMap<>();
        // 获取参数
        String config = Global.getConfig("sys.yzw.switch");
        // 是否启用易政网首页接口推送功能：0为关闭
        if (!"0".equals(config)) {
            // 开启易政网功能
            if (yzwProperties.isYzwFunc()) {
                // 校验token
                if (StringUtils.isNotBlank(token)) {
                    // 验证当前登录用户
                    JSONObject resultObj = yzwClient.checkLxLoginObj(Constant.TestData.CURRENT_USER_ID, token);
                    if (null != resultObj) {
                        // 获取当前登录用户在本系统中的信息
                        String id = resultObj.getString("id");
                        Map paramMap = new HashMap();
                        paramMap.put("status", "0");
                        paramMap.put("extendS2", id);
                        Map user = yzwService.findYzwList(paramMap);
                        if (null != user) {
                            String userCode = (String) user.get("user_code");
                            Integer markCount;
                            if ("1".equals(config)) {
                                // 推送站内信
                                // 获取当前用户的消息
                                MsgPush msgPush = new MsgPush();
                                if (StringUtils.isBlank((msgPush).getMsgType())) {
                                    msgPush.setMsgType("pc");
                                }
                                msgPush.setPlanPushDate_lte(new Date());
                                msgPush.setReceiveUserCode(msgPush.getCurrentUser().getUserCode());
                                msgPush.setPage(new Page(1, 10));

                                msgPush.setReceiveCode(userCode);
                                msgPush.setReceiveUserCode(userCode);

                                // 查询信息并处理
                                Page<MsgPush> currentPage = msgPushService.findPage(msgPush);
                                markCount = (int) currentPage.getCount();
                            } else {
                                // 推送待办
                                markCount = dcSupBacklogService.getCountByUserCode(userCode);
                            }

                            // 构建返回值
                            message.put("code", "000000");
                            message.put("message", "成功");
                            message.put("data", markCount);
                            message.put("success", "true");
                        } else {
                            message.put("code", "999999");
                            message.put("message", "用户不存在，请联系管理员");
                        }
                    } else {
                        message.put("code", "999999");
                        message.put("message", "易政网信息验证失败");
                    }
                } else {
                    message.put("code", "999999");
                    message.put("message", "请求参数中token不存在，请刷新后重试");
                }
            } else {
                message.put("code", "999999");
                message.put("message", "易政网登录开关未开启");
            }
        } else {
            message.put("code", "999999");
            message.put("message", "接口暂时关闭");
        }

        return message;
    }

    /**
     * 获取消息中，按钮的跳转地址
     *
     * @param msgId
     * @return
     */
    private String getMsgButtonHref(String msgId) {
        String buttonHref = "";

        try {
            // 获取消息体
            MsgPush msgPush = msgPushService.get(new MsgPush(msgId));
            if (msgPush != null) {
                // 获取消息内容
                JSONObject msgContentObj = JSON.parseObject(msgPush.getMsgContent());
                // 获取按钮组
                JSONArray buttonsArray = msgContentObj.getJSONArray("buttons");
                if (buttonsArray != null && buttonsArray.size() > 0) {
                    // 获取按钮
                    JSONObject buttonObj = JSON.parseObject(buttonsArray.getString(0));
                    // 获取按钮跳转地址
                    buttonHref = buttonObj.getString("href");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return buttonHref;
    }

    /**
     * 消息分页查询，易政网查询当前登录用户的待办信息
     * 推送站内信方法
     *
     * @param pager
     * @param user
     * @return
     */
    private Pager getMsgDetail1(Pager pager, Map user) {
        // 获取当前用户的消息
        String userCode = (String) user.get("user_code");
        String userName = (String) user.get("user_name");

        // 获取站内信
        MsgPush msgPush = new MsgPush();
        if (StringUtils.isBlank((msgPush).getMsgType())) {
            msgPush.setMsgType("pc");
        }
        msgPush.setPlanPushDate_lte(new Date());
        msgPush.setReceiveUserCode(msgPush.getCurrentUser().getUserCode());
        msgPush.setPage(new Page(pager.getPageNo(), pager.getPageSize()));

        msgPush.setReceiveCode(userCode);
        msgPush.setReceiveUserCode(userCode);

        // 查询信息并处理
        Page<MsgPush> currentPage = msgPushService.findPage(msgPush);
        List<MsgPush> currentList = currentPage.getList();
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (MsgPush push : currentList) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", push.getId());
            map.put("regid", push.getBizKey());
            map.put("ntdate", DateUtils.formatDate(push.getPushDate(), "yyyy-MM-dd"));
            map.put("nttime", DateUtils.formatDate(push.getPushDate(), "HH:mm:ss"));
            map.put("channel", "JDBC");
            map.put("optid", push.getSendUserCode());
            map.put("optname", push.getSendUserName());
            map.put("operation", push.getBizType());
            map.put("msgtpl", "");
            map.put("msgtplseqno", "");
            map.put("mesg", push.getMsgContentEntity().get("content"));
            map.put("msgurl", "news?msgId=" + push.getId());
            map.put("msgparams", "");
            map.put("subjectid", userCode);
            map.put("subjectnm", userName);
            map.put("type", "1");
            map.put("readflag", "0");
            map.put("issend", push.getPushStatus());
            map.put("ishandle", "");
            map.put("optime", push.getSendDate());
            map.put("compid", "");
            map.put("remarks1", "");
            map.put("remarks2", "");
            map.put("remarks3", "");
            map.put("remarks4", "");
            resultList.add(map);
        }

        // 构建查询结果
        Pager resultPager = new Pager();
        resultPager.setPageNo(currentPage.getPageNo());
        resultPager.setPageSize(currentPage.getPageSize());
        resultPager.setSort("");
        resultPager.setTotalPages((int) Math.ceil((double) currentPage.getCount() / currentPage.getPageSize()));
        resultPager.setTotalRows((int) currentPage.getCount());
        resultPager.setUseSort(false);
        resultPager.setRows(resultList);

        return resultPager;
    }

    /**
     * 消息分页查询，易政网查询当前登录用户的待办信息
     * 推送待办方法
     *
     * @param pager
     * @param user
     * @return
     */
    private Pager getMsgDetail2(Pager pager, Map user) {
        // 获取当前用户的消息
        String userCode = (String) user.get("user_code");
        String userName = (String) user.get("user_name");

        // 获取待办
        DcSupBacklog dcSupBacklog = new DcSupBacklog();
        dcSupBacklog.setReceiveUserCode(userCode);
        dcSupBacklog.setPage(new Page(pager.getPageNo(), pager.getPageSize()));
        Page<DcSupBacklog> currentPage = dcSupBacklogService.getListByUserCode(dcSupBacklog);

        List<DcSupBacklog> currentList = currentPage.getList();
        List<Map<String, Object>> resultList = new ArrayList<>();
        for (DcSupBacklog backlog : currentList) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", backlog.getId());
            map.put("regid", backlog.getBizKey());
            map.put("ntdate", DateUtils.formatDate(backlog.getCreateDate(), "yyyy-MM-dd"));
            map.put("nttime", DateUtils.formatDate(backlog.getCreateDate(), "HH:mm:ss"));
            map.put("channel", "JDBC");
            map.put("optid", backlog.getSendUserCode());
            map.put("optname", backlog.getSendUserName());
            map.put("operation", backlog.getBizType());
            map.put("msgtpl", "");
            map.put("msgtplseqno", "");
            map.put("mesg", backlog.getBacklogContent());
            map.put("msgurl", "news?msgId=" + backlog.getId());
            map.put("msgparams", "");
            map.put("subjectid", userCode);
            map.put("subjectnm", userName);
            map.put("type", "1");
            map.put("readflag", "0");
            map.put("issend", "1");
            map.put("ishandle", "");
            map.put("optime", "");
            map.put("compid", "");
            map.put("remarks1", "");
            map.put("remarks2", "");
            map.put("remarks3", "");
            map.put("remarks4", "");
            resultList.add(map);
        }

        // 构建查询结果
        Pager resultPager = new Pager();
        resultPager.setPageNo(currentPage.getPageNo());
        resultPager.setPageSize(currentPage.getPageSize());
        resultPager.setSort("");
        resultPager.setTotalPages((int) Math.ceil((double) currentPage.getCount() / currentPage.getPageSize()));
        resultPager.setTotalRows((int) currentPage.getCount());
        resultPager.setUseSort(false);
        resultPager.setRows(resultList);

        return resultPager;
    }

    /**
     * 获取皖政通环境
     *
     * @param tokenId
     * @param remoteIp
     * @return
     */
    @RequestMapping("/getwztUser")
    public String getwztUser(@RequestParam("tokenId") String tokenId, @RequestParam("remoteIp") String remoteIp, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String, String> map = new HashMap<>();
        map.put("appId", "wzt");
        map.put("tokenId", tokenId);
        map.put("remoteIp", remoteIp);
        map.put("attributeNames", "loginName,userid");
        String wzt_url = Global.getConfig("platform.wzt.url");
        String s = HttpClientUtils.ajaxPost(wzt_url + "/idp/restful/getIDPUserAttributes", map);
        JSONObject json = JSONObject.parseObject(s);
        String userId = json.getJSONObject("data").getJSONObject("attributes").getString("userid");
        User userByUserCode = yzwService.getUserByUserCode(userId);
        if (StringUtils.isNotBlank(userByUserCode.getLoginCode())) {
            String ssoToken = UserUtils.getSsoToken(userByUserCode.getLoginCode());
            Map userMap = new HashMap();
            userMap.put("username", userByUserCode.getLoginCode());
            userMap.put("token", ssoToken);
            return ServletUtils.renderResult(response, Global.TRUE, text("执行成功"), userMap);
        } else {
            request.setAttribute("message", "用户不存在，请联系管理员");
            request.getRequestDispatcher("/error/403").forward(request, response);
        }
        return REDIRECT + "/a/login";
    }



    /**
     * 新增皖政通待办
     * @return
     */
    public static String addWZTPending(Map<String,String> data,List<Map<String,String>> user){
        try {
            //获取header必须的参数  x-tif-paasid  x-tif-timestamp  x-tif-nonce  x-tif-signature
//            String db_url = Global.getConfig("platform.wzt.ipport");
            String db_url = "https://smartgatezs.wstwx.ahzwfw.gov.cn/ebus/wzt_to_yth";
//            String paasid = Global.getConfig("platform.wzt.passid");
            String paasid = "wzt_to_yth";
            String timestamp = System.currentTimeMillis()/1000+"";
//            String token = Global.getConfig("platform.wzt.token");
            String token = "GVI5JJVaJnv4I5ytlPqzlYHcOhZjjXOF";
            String nonce = UUID.randomUUID().toString().replace("-","");
            //sha256(x-rio-timestamp + Token + x-rio-nonce + x-rio-timestamp)
            String signatureString = timestamp+token+nonce+timestamp;
            String signature = SM3Utils.getsha256(signatureString);
            Map<String,String> header = new HashMap<>();
            header.put("x-tif-paasid",paasid);
            header.put("x-tif-timestamp",timestamp);
            header.put("x-tif-nonce",nonce);
            header.put("x-tif-signature",signature);
            //调用皖政通新增接口
            Map<String,Object> dataMap = new HashMap<>();
//            dataMap.put("appCode",Global.getConfig("platform.wzt.appCode"));//新增时必填，一体化平台发布时生成的应用ID（皖政通运营人员提供）
            dataMap.put("appCode","3d30cfbfb465fcd758f3a1a43584ae2d");//新增时必填，一体化平台发布时生成的应用ID（皖政通运营人员提供）
            dataMap.put("appName","智慧督查");//新增时必填，所属系统名称
            dataMap.put("vendorId",data.get("id"));//新增时必填，第三方系统待办主键
            dataMap.put("source","1");//新增时必填，来源类型1：第三方
            dataMap.put("title",data.get("title"));//新增时必填，标题
            dataMap.put("message",data.get("message"));//新增时必填,待办描述
            dataMap.put("content","");//办理提示内容
            dataMap.put("kind","8");//新增时必填，待办类型1：公文待办，2：公文待阅，3：邮件，4：会议，5：审批 6：监督 7. 考勤8. 其他
            dataMap.put("priority","2");//新增时必填，紧急程度1-特提、2-特急、3-加急、4-平急、5-普通
            dataMap.put("appUrl","http://10.1.50.222:16667/h5");//新增时必填，移动端处理链接 http://xxxxx
            dataMap.put("pcUrl","http://10.1.50.222:16667/whdc/a");//新增时必填，PC端处理链接 http://xxxxx
            dataMap.put("syncStatusUrl","http://10.1.50.222:16667/whdc/a");//新增时必填，处理状态同步 url
            dataMap.put("senderId",data.get("senderId"));//新增时必填，发送人竹云id
            dataMap.put("senderName",data.get("senderName"));//新增时必填，发送人名
            dataMap.put("onlyForOperator","1");//新增时必填，是否仅对执行人展示1-是，2-否
            dataMap.put("infoType","1");//新增时必填，待办通知类型;1- 站内信， 2-短信
            dataMap.put("startTime",DateUtils.formatDate(new Date(),"yyyy-MM-dd HH:mm:ss"));//新增时必填，待办开始时间 时间格式 ： yyyy-MM-dd HH:mm:ss
            dataMap.put("endTime","2024-12-12 23:59:59");//新增时必填，待办截止时间 时间格式 ： yyyy-MM-dd HH:mm:ss
            dataMap.put("executorList",user);//新增时必填，执行人信息集，格式[{userId:"",userName:""}]
            dataMap.put("relativerList",new ArrayList<>());//相关人信息集，格式[{userId:"",userName:""}]


            JSONObject json = new JSONObject(dataMap);
            String dataStr = json.toJSONString();

            String s = OkHttpUtils.httpPostWZT(db_url + "/moap/restful/todo/settingPendingInfo/put", dataStr, header);
            System.out.println(s);
            return s;
        }catch(Exception e){
            return "失败";
        }

    }

    /**
     * 皖政通待办置为已办
     * @param vendorId 待办表id
     * @param bambooUserId 竹云用户id
     * @return
     */
    public static String dealWZTPending(String vendorId,String bambooUserId){
        try{
            //获取header必须的参数  x-tif-paasid  x-tif-timestamp  x-tif-nonce  x-tif-signature
    //            String db_url = Global.getConfig("platform.wzt.ipport");
            String db_url = "https://smartgatezs.wstwx.ahzwfw.gov.cn/ebus/wzt_to_yth";
    //            String paasid = Global.getConfig("platform.wzt.passid");
            String paasid = "wzt_to_yth";
            String timestamp = System.currentTimeMillis()/1000+"";
    //            String token = Global.getConfig("platform.wzt.token");
            String token = "GVI5JJVaJnv4I5ytlPqzlYHcOhZjjXOF";
            String nonce = UUID.randomUUID().toString().replace("-","");
            //sha256(x-rio-timestamp + Token + x-rio-nonce + x-rio-timestamp)
            String signatureString = timestamp+token+nonce+timestamp;
            String signature = SM3Utils.getsha256(signatureString);
            Map<String,String> header = new HashMap<>();
            header.put("x-tif-paasid",paasid);
            header.put("x-tif-timestamp",timestamp);
            header.put("x-tif-nonce",nonce);
            header.put("x-tif-signature",signature);

            Map<String,Object> dataMap = new HashMap<>();
    //        dataMap.put("appCode",Global.getConfig("platform.wzt.appCode"));//一体化平台发布时生成的应用ID（皖政通运营人员提供）
            dataMap.put("appCode","3d30cfbfb465fcd758f3a1a43584ae2d");//一体化平台发布时生成的应用ID（皖政通运营人员提供）
            dataMap.put("vendorId",vendorId);//三方业务系统待办 id
            dataMap.put("bambooUserId",bambooUserId);//当前登录的竹云用户 ID

            JSONObject json = new JSONObject(dataMap);
            String dataStr = json.toJSONString();

            String s = OkHttpUtils.httpPostWZT(db_url + "/moap/restful/todo/settingPendingInfo/deal-pending", dataStr, header);
            System.out.println(s);
            return s;
        }catch(Exception e){
            return "失败";
        }
    }

    /**
     * 删除待办已办
     * @param vendorId
     * @param bambooUserId
     * @return
     */
    public static String deleteWZTPending(String vendorId,String bambooUserId){
        try{
            //获取header必须的参数  x-tif-paasid  x-tif-timestamp  x-tif-nonce  x-tif-signature
    //            String db_url = Global.getConfig("platform.wzt.ipport");
            String db_url = "https://smartgatezs.wstwx.ahzwfw.gov.cn/ebus/wzt_to_yth";
    //            String paasid = Global.getConfig("platform.wzt.passid");
            String paasid = "wzt_to_yth";
            String timestamp = System.currentTimeMillis()/1000+"";
    //            String token = Global.getConfig("platform.wzt.token");
            String token = "GVI5JJVaJnv4I5ytlPqzlYHcOhZjjXOF";
            String nonce = UUID.randomUUID().toString().replace("-","");
            //sha256(x-rio-timestamp + Token + x-rio-nonce + x-rio-timestamp)
            String signatureString = timestamp+token+nonce+timestamp;
            String signature = SM3Utils.getsha256(signatureString);
            Map<String,String> header = new HashMap<>();
            header.put("x-tif-paasid",paasid);
            header.put("x-tif-timestamp",timestamp);
            header.put("x-tif-nonce",nonce);
            header.put("x-tif-signature",signature);

            Map<String,Object> dataMap = new HashMap<>();
    //        dataMap.put("appCode",Global.getConfig("platform.wzt.appCode"));//一体化平台发布时生成的应用ID（皖政通运营人员提供）
            dataMap.put("appCode","3d30cfbfb465fcd758f3a1a43584ae2d");//一体化平台发布时生成的应用ID（皖政通运营人员提供）
            dataMap.put("vendorId",vendorId);//三方业务系统待办 id
            dataMap.put("bambooUserId",bambooUserId);//当前登录的竹云用户 ID

            JSONObject json = new JSONObject(dataMap);
            String dataStr = json.toJSONString();

            String s = OkHttpUtils.httpPostWZT(db_url + "/moap/restful/todo/settingPendingInfo/delete-pending", dataStr, header);
            System.out.println(s);
            return s;
        }catch(Exception e){
            return "失败";
        }
    }

    public static void main(String[] args) {
        Map<String,String> data = new HashMap<>();
        data.put("id","4bf51f8e169044eead69001f8");
        data.put("title","审批");
        data.put("message","您有一条新任务反馈待审批");
        data.put("senderId","20230310145625426-3394-582047FBC");
        data.put("senderName","haocheng");

        Map map = new HashMap();
            map.put("userId","20230310145643302-DCE0-46BA6BADA");
            map.put("userName","doubaolin");
        List<Map<String,String>> user = new ArrayList<>();
            user.add(map);
//        addWZTPending(data,user);

//        dealWZTPending("4bf51f8e169044eead69001f8","20230310145625426-3394-582047FBC");
        deleteWZTPending("4bf51f8e169044eead69001f8","20230310145625426-3394-582047FBC");
    }
}
